/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Module Name          : com.yaodian100.mall.merchandize.web.MerchandizeAction
Module Description   :

Date Created      : 2010/1/15
Original Author   : andy.chuang
Team              : yaodian100
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MODIFICATION HISTORY
------------------------------------------------------------------------------
Date Modified       Modified by       Comments
------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.mall.merchandize.web;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.core.common.entity.SimplePager;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.BaseManager;
import com.yaodian100.core.common.service.DomainService;
import com.yaodian100.core.common.utils.HtmlRegexUtil;
import com.yaodian100.core.common.utils.ServerValue;
import com.yaodian100.core.menu.entity.Menu;
import com.yaodian100.crm.cs.service.CsService;
import com.yaodian100.ec.campaign.entity.Campaign;
import com.yaodian100.ec.campaign.entity.CampaignExtend;
import com.yaodian100.ec.campaign.service.CampaignService;
import com.yaodian100.ec.category.entity.Category;
import com.yaodian100.ec.category.service.CategoryService;
import com.yaodian100.ec.creditcard.entity.Creditcard;
import com.yaodian100.ec.creditcard.service.CreditcardService;
import com.yaodian100.ec.member.entity.ImageValid;
import com.yaodian100.ec.member.service.MemberService;
import com.yaodian100.ec.product.entity.AddOnProduct;
import com.yaodian100.ec.product.entity.AddOnProductPage;
import com.yaodian100.ec.product.entity.Brand;
import com.yaodian100.ec.product.entity.DaphneProduct;
import com.yaodian100.ec.product.entity.OrderComment;
import com.yaodian100.ec.product.entity.Product;
import com.yaodian100.ec.product.entity.ProductComment;
import com.yaodian100.ec.product.entity.Specification;
import com.yaodian100.ec.product.entity.SpecificationInventory;
import com.yaodian100.ec.product.entity.SpecificationMajor;
import com.yaodian100.ec.product.entity.OrderComment.COMMENT_STATUS;
import com.yaodian100.ec.product.service.AndeProductService;
import com.yaodian100.ec.product.service.DaphneProductService;
import com.yaodian100.ec.product.service.OrderCommentService;
import com.yaodian100.ec.product.service.Product2Service;
import com.yaodian100.ec.product.service.ProductService;
import com.yaodian100.ec.shelf.entity.Shelf;
import com.yaodian100.ec.shelf.entity.ViewShelfProduct;
import com.yaodian100.ec.shelf.service.ShelfService;
import com.yaodian100.ec.supplierapply.entity.SupplierApply;
import com.yaodian100.ec.supplierapply.service.SupplierApplyService;
import com.yaodian100.ec.timelimitsale.service.TimeLimitSaleService;
import com.yaodian100.mall.member.util.UserData;

/**
 * @author andy.chuang
 * 
 */
public class MerchandizeAction extends ActionSupport {
	private final Logger logger = LoggerFactory.getLogger(MerchandizeAction.class);
	private static final long serialVersionUID = 1311702057387073712L;
	@Resource
	private MemberService memberService;
	@Resource
	private CsService csService;
	@Resource
	private BaseManager baseMgr;
	@Resource
	private CampaignService campaignService;
	@Autowired
	private CategoryService categoryService;
	@Resource
	private DaphneProductService daphneProductService;
	@Resource
	private ProductService productService;
	@Resource
	private TimeLimitSaleService timeLimitSaleService;
	@Resource
	private ShelfService shelfService;
	@Resource
	private SupplierApplyService supplierApplyService;
	@Autowired
	private CreditcardService creditcardService;
	@Autowired
	private DomainService<Menu> menuService;
	@Autowired
	private Product2Service product2Service;
	@Autowired
	private AndeProductService andeProductService;
	@Resource
	private OrderCommentService orderCommentService;

	private Product product;
	private Brand brand;
	private Shelf shelf;
	private String outSaleType;
	private String tempZId;
	private String nmProductId;

	private String questionContent;

	private String validValue;

	private String productId;

	private String isMember;

	private String email;

	private String sysStatus;

	private String sysMessage;

	private String z;
	private String campaignCookie;
	private List<Campaign> productCampaigns;
	private String pageTitle;
	private String pageDescription;
	private String pageKeywords;
	private Category productCategory;
	private boolean hasTlProduct;// 限时抢购商品
	private boolean hasAndeProduct;// 安德仓库商品
	private Map<String, Boolean> resultDaphne;
	private List<ViewShelfProduct> mpvList;
	private String clearPV;
	private int hotSaleInventory;
	private int addOnInv;
	private SupplierApply supplierApply;
	private Map<String, Map<Long, Integer>> addOnProdTypeInvMap;// NM、ADDON、PRESENT可售数
	private Map<String, List<AddOnProductPage>> addOnProdTypeMap;// ADDON、PRESENT商品资料
	private Map<String, List<Specification>> prodSpecMap;
	private Map<String, List<SpecificationMajor>> prodSpecMajorMap;
	private Map<String, SpecificationInventory> prodInvMap; // nmDetail
	private String mainReturnRule; // nmDetail
	private Creditcard creditcard;// 信用卡分期
	private Menu billBankCodeMenu; // 與 getter, setter
	private Menu billBankSingleCodeMenu; // 快钱menu code單期支付

	private String prodRecommends;
	private List<Product> prodRecommendList;
	private UserData prodUserData;
	/**
	 * 用於讓前端讀取 z 的 category 和這個 category 的其他屬性，目前有 categorynav 會用到
	 */
	private Category categoryOfZ;
	private boolean isVolumeOfProduct;
	private boolean chkAvailableDetails;

	// 商品评论
	private ProductComment productComment;
	private String star;
	private String commentTp;
	private List<OrderComment> commentProductList;
	private SimplePager pager;
	private String last3Comment = "";
	private Map<String, ProductComment> addProdCommentMap;
	private Map<String, ProductComment> nmProdCommentMap;
	private String actionResult;
	private List<Object> orderCommentList;
	private String[] orderComtOrderId;
	private String[] contentdata;
	private String[] orderComtSubject;
	private String[] sizedata;
	private String[] orderComtScore;
	private String[] orderComtProductId;
	private String[] orderComtOrderDetailId;
	private String redirect_url;
	private String[] nocomment;
	private Campaign commentCampaign;
	private String[] mainProductId;

	/**
	 * @return the productCategory
	 */
	public Category getProductCategory() {
		return productCategory;
	}

	/**
	 * @param productCategory the productCategory to set
	 */
	public void setProductCategory(Category productCategory) {
		this.productCategory = productCategory;
	}

	public String addOnProductInfo() {
		prodInvMap = productService.getSpecificationInventoryMap(productId);
		Product nmProduct = (Product) baseMgr.get(Product.class, nmProductId);
		mainReturnRule = nmProduct.getReturnRule();

		// 商品评价
		productComment = orderCommentService.getProductCommentByProductId(productId);
		if (null != productComment) {
			star = "0";
			if (productComment.getAvgScore().movePointRight(1).intValue() % 10 > 0) {
				star = "5";
			}
		}
		CommonCriteria crit = new CommonCriteria();

		crit.addEq("productId", productId);
		crit.addEq("hideYn", "N");
		crit.addEq("commentStatus", COMMENT_STATUS.APPROVE.getValue());
		if (StringUtils.isNotBlank(commentTp)) {
			if ("Good".equals(commentTp)) {
				ArrayList<BigDecimal> seList = new ArrayList<BigDecimal>();
				seList.add(new BigDecimal("5"));
				seList.add(new BigDecimal("4"));
				crit.addIn("score", seList);
			}
			if ("Mid".equals(commentTp)) {
				ArrayList<BigDecimal> seList = new ArrayList<BigDecimal>();
				seList.add(new BigDecimal("3"));
				seList.add(new BigDecimal("2"));
				crit.addIn("score", seList);
			}
			if ("Low".equals(commentTp)) {
				crit.addEq("score", new BigDecimal("1"));
			}
		}
		if (pager == null) {
			pager = new SimplePager();
		}
		int entitySize = orderCommentService.getListSize(crit).intValue();
		pager.setPageRecord(10);
		pager.setTotalSize(entitySize);
		commentProductList = orderCommentService.getList(pager.getCurrentPage() * pager.getPageRecord(), pager
				.getPageRecord(), crit, new String[] { "approveDate desc" });

		String logId = "";
		for (OrderComment ocomt : commentProductList) {
			logId = StringUtils.overlay(StringUtils.defaultString(ocomt.getLoginId()), "***",
					ocomt.getLoginId().length() - 3, ocomt.getLoginId().length());
			ocomt.setLoginId(logId);
		}

		// 前三位评价用户
		List<OrderComment> last3Comments = orderCommentService.getLast3CommentByProductId(productId);
		if (null != last3Comments) {
			int sizeLast3Comment = 0;
			if (last3Comments.size() >= 3) {
				sizeLast3Comment = 3;
			} else {
				sizeLast3Comment = last3Comments.size();
			}
			if (sizeLast3Comment > 0) {
				for (int i = 0; i < sizeLast3Comment; i++) {
					OrderComment oc = last3Comments.get(i);
					if (oc.getLoginId().length() < 4) {
						last3Comment = last3Comment + oc.getLoginId().substring(0, 1) + "**" + ",";
					} else {
						last3Comment = last3Comment
								+ StringUtils.overlay(StringUtils.defaultString(oc.getLoginId()), "***" + ",",
										oc.getLoginId().length() - 3, oc.getLoginId().length());
					}
				}
				last3Comment = last3Comment.substring(0, last3Comment.length() - 1);
			}
		}
		return "nmDetail";
	}

	private boolean checkCode(String imageId, String inputCode) {
		ImageValid imageValid = new ImageValid();
		imageValid.setId(imageId);
		imageValid.setValidData(inputCode);
		try {
			memberService.isImageValid(imageValid);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	public String createQuestion() {
		Product product = (Product) baseMgr.get(Product.class, productId);
		this.product = product;
		Category category = (Category) baseMgr.get(Category.class, new Long(product.getMainCategoryID()));
		((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().setAttribute("category",
				category);
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		UserData userData = new UserData(request, response);
		if (!checkCode(userData.getImageValid(), validValue)) {
			sysStatus = "0";
			sysMessage = "验证码错误！";
		} else {
			String memberId = "";
			if (userData != null) {
				if (userData.getMemberId() != null) {
					memberId = userData.getMemberId();
				}
			}
			if (isMember == null || isMember.length() == 0) {
				isMember = "true";
			}
			String content = HtmlRegexUtil.secureMatch(questionContent);
			csService.createProductQuestion(Boolean.valueOf(isMember), email, memberId, productId, content);
			sysStatus = "1";
			sysMessage = "您的问题已经提交！<br/>当问题被回覆后，您的问答记录就会显示在商品页中。";
		}
		return "createQuestion";
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @return the isMember
	 */
	public String getIsMember() {
		return isMember;
	}

	/**
	 * @return the outSaleType
	 */
	public String getOutSaleType() {
		return outSaleType;
	}

	/**
	 * @return the product
	 */
	public Product getProduct() {
		return product;
	}

	/**
	 * @return the productCampaigns
	 */
	public List<Campaign> getProductCampaigns() {
		return productCampaigns;
	}

	/**
	 * @return the productId
	 */
	public String getProductId() {
		return productId;
	}

	/**
	 * @return the questionContent
	 */
	public String getQuestionContent() {
		return questionContent;
	}

	/**
	 * @return the sysMessage
	 */
	public String getSysMessage() {
		return sysMessage;
	}

	/**
	 * @return the sysStatus
	 */
	public String getSysStatus() {
		return sysStatus;
	}

	public String getTempZId() {
		return tempZId;
	}

	/**
	 * @return the validValue
	 */
	public String getValidValue() {
		return validValue;
	}

	/**
	 * @return the z
	 */
	public String getZ() {
		return z;
	}

	public CategoryService getCategoryService() {
		return this.categoryService;
	}

	/**
	 * 用於讓前端讀取 z 的 category 和這個 category 的其他屬性，目前有 categorynav 會用到
	 */
	public Category getCategoryOfZ() {
		return this.categoryOfZ;
	}

	public String nmDetail() {
		prodInvMap = productService.getSpecificationInventoryMap(productId);
		commentCampaign = campaignService.getActiveBonusCampaignByM04(null);
		// 商品评价
		productComment = orderCommentService.getProductCommentByProductId(productId);
		if (null != productComment) {
			star = "0";
			if (productComment.getAvgScore().movePointRight(1).intValue() % 10 > 0) {
				star = "5";
			}
		}
		CommonCriteria crit = new CommonCriteria();

		crit.addEq("productId", productId);
		crit.addEq("hideYn", "N");
		crit.addEq("commentStatus", COMMENT_STATUS.APPROVE.getValue());
		if (StringUtils.isNotBlank(commentTp)) {
			if ("Good".equals(commentTp)) {
				ArrayList<BigDecimal> seList = new ArrayList<BigDecimal>();
				seList.add(new BigDecimal("5"));
				seList.add(new BigDecimal("4"));
				crit.addIn("score", seList);
			}
			if ("Mid".equals(commentTp)) {
				ArrayList<BigDecimal> seList = new ArrayList<BigDecimal>();
				seList.add(new BigDecimal("3"));
				seList.add(new BigDecimal("2"));
				crit.addIn("score", seList);
			}
			if ("Low".equals(commentTp)) {
				crit.addEq("score", new BigDecimal("1"));
			}
		}
		if (pager == null) {
			pager = new SimplePager();
		}
		int entitySize = orderCommentService.getListSize(crit).intValue();
		pager.setPageRecord(10);
		pager.setTotalSize(entitySize);
		commentProductList = orderCommentService.getList(pager.getCurrentPage() * pager.getPageRecord(), pager
				.getPageRecord(), crit, new String[] { "approveDate desc" });

		String logId = "";
		for (OrderComment ocomt : commentProductList) {
			logId = StringUtils.overlay(StringUtils.defaultString(ocomt.getLoginId()), "***",
					ocomt.getLoginId().length() - 3, ocomt.getLoginId().length());
			ocomt.setLoginId(logId);
		}

		// 前三位评价用户
		List<OrderComment> last3Comments = orderCommentService.getLast3CommentByProductId(productId);
		if (null != last3Comments) {
			int sizeLast3Comment = 0;
			if (last3Comments.size() >= 3) {
				sizeLast3Comment = 3;
			} else {
				sizeLast3Comment = last3Comments.size();
			}
			if (sizeLast3Comment > 0) {
				for (int i = 0; i < sizeLast3Comment; i++) {
					OrderComment oc = last3Comments.get(i);
					if (oc.getLoginId().length() < 4) {
						last3Comment = last3Comment + oc.getLoginId().substring(0, 1) + "**" + ",";
					} else {
						last3Comment = last3Comment
								+ StringUtils.overlay(StringUtils.defaultString(oc.getLoginId()), "***" + ",",
										oc.getLoginId().length() - 3, oc.getLoginId().length());
					}
				}
				last3Comment = last3Comment.substring(0, last3Comment.length() - 1);
			}
		}
		return "nmDetail";
	}

	public String presentProductInfo() {
		return "presentProductInfo";
	}

	/**
	 * @param campaignCookie the campaignCookie to set
	 */
	public void setCampaignCookie(String campaignCookie) {
		this.campaignCookie = campaignCookie;
	}

	public String jsonClearPV() {
		try {
			HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(
					ServletActionContext.HTTP_REQUEST);
			HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
					ServletActionContext.HTTP_RESPONSE);
			UserData userData = new UserData(request, response);
			userData.clear(userData.NAME_YAODIAN100_MEMBER_PV);
			userData.writeValue(userData.NAME_YAODIAN100_MEMBER_PV, "");
			mpvList = null;
			clearPV = "true";
		} catch (Exception e) {
			clearPV = "false";
		}
		return "jsonClearPV";
	}

	public String product() {
		if (StringUtils.isBlank(productId) || StringUtils.length(productId) < 8 || !NumberUtils.isNumber(productId)) {
			return "outSale";
		}
		Product product = (Product) baseMgr.get(Product.class, productId);
		if (product == null) {
			return "outSale";
		}
		this.product = product;
		this.shelf = shelfService.getActiveShelfByProductId(productId);
		if (product.getIsDelete().equals("Y") || this.shelf == null || product.getProductType() == 2
				|| product.getProductType() == 3) {
			outSaleType = "0";
			if (product.getProductType() == 2 || product.getProductType() == 3) {
				outSaleType = "1";
			} else {
				outSaleType = "0";
			}
			return "outSale";
		} else {
			supplierApply = supplierApplyService.get(product.getSupplierId());
			Category category = (Category) baseMgr.get(Category.class, new Long(product.getMainCategoryID()));
			productCategory = category;
			if ("0".equals(category.getLevel())) {
				if (category.getId() < 10) {
					tempZId = "0" + category.getId().toString();
				} else {
					tempZId = category.getId().toString();
				}
			} else {
				if (Integer.parseInt(category.getCategoryPath().split("/")[0]) < 10) {
					tempZId = "0" + category.getCategoryPath().split("/")[0];
				} else {
					tempZId = category.getCategoryPath().split("/")[0];
				}
			}
			((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().setAttribute("category",
					category);

			HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(
					ServletActionContext.HTTP_REQUEST);
			HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
					ServletActionContext.HTTP_RESPONSE);
			HttpSession session = request.getSession();
			UserData userData = new UserData(request, response);
			Map optional = new HashMap();
			optional.put("domain", request.getServerName());
			// campaignCookie for capture
			if (StringUtils.isBlank(campaignCookie)) {
				optional.put("cookie", userData.getApplySource());
			} else {
				optional.put("cookie", campaignCookie);
			}
			// if (product.getProductType() != Integer.valueOf(Product.PRODUCT_TYPE.NPICKM.getValue())) {
			if (z != null && z.length() > 0) {
				productCampaigns = campaignService.getValidCampaign(z, product.getProductId(), optional);
			} else {
				productCampaigns = campaignService.getValidCampaign(category.getCategoryPath(), product.getProductId(),
						optional);
			}
			// }
			Category rootCategory = (Category) baseMgr
					.get(Category.class, new Long(category.getCategoryPath().split("/")[0]));
			pageTitle = product.getProductName() + " - " + rootCategory.getName() + " - 耀点100";
			pageDescription = product.getProductName() + " - " + rootCategory.getName() + " - 耀点100";
			String categorySeo = ServerValue.getSeoProp().getProperty(category.getId().toString() + ".keywords");// for seo 使用
			String categoryNamePath;
			if (z != null) {
				Category categoryOfZ = categoryService.getCategoryById(Long.parseLong(z));
				setCategoryOfZ(categoryOfZ);
				categoryNamePath = categoryService.makeCategorieURL(categoryOfZ.getId(), false);
			} else {
				categoryNamePath = categoryService.makeCategorieURL(category.getId(), false);
			}
			pageKeywords = StringUtils.isNotBlank(categorySeo) ? (categorySeo + ",") : ""
					+ categoryNamePath.replaceAll(" &gt; ", ",")
					+ (StringUtils.isNotBlank(product.getProductKeyword()) ? ("," + product.getProductKeyword()) : "");
			resultDaphne = chkDaphneProduct(product);

			hasTlProduct = timeLimitSaleService.isTimeLimitSale(productId);
			String memberPV = userData.readValue(UserData.NAME_YAODIAN100_MEMBER_PV);
			if (null == memberPV) {
				userData.writeValue(UserData.NAME_YAODIAN100_MEMBER_PV, productId + ",");
			} else {
				if (memberPV.indexOf(productId) == -1) {
					if (StringUtils.countMatches(memberPV, ",") >= 10) {
						// 大於十筆, 保留後九筆商品資料 (八碼+",")*9=81
						if (memberPV.length() > 81) {
							memberPV = memberPV.substring(memberPV.length() - 81);
						}
					}
					userData.writeValue(UserData.NAME_YAODIAN100_MEMBER_PV, memberPV + productId + ",");
				}
			}
			// 我的浏览记录
			String mpv = userData.readValue(UserData.NAME_YAODIAN100_MEMBER_PV);
			if (StringUtils.isNotBlank(mpv)) {
				String[] mpvs = StringUtils.split(mpv, ",");
				mpvList = new ArrayList<ViewShelfProduct>();
				List<ViewShelfProduct> vsps = null;
				CommonCriteria crit = null;
				ArrayUtils.reverse(mpvs);
				for (String pv : mpvs) {
					crit = new CommonCriteria();
					crit.addEq("productId", pv);
					crit.addEq("isDelete", "N");
					vsps = shelfService.getViewShelfProduct(crit, null, 0, 1);
					if (null != vsps && vsps.size() == 1) {
						mpvList.add(vsps.get(0));
					}
				}
				if (mpvList.size() > 10) {
					mpvList = mpvList.subList(0, 10);
					userData.writeValue(UserData.NAME_YAODIAN100_MEMBER_PV, (ArrayUtils.toString(ArrayUtils.subarray(mpvs,
							mpvs.length - 10, mpvs.length))).replaceAll("{", "").replaceAll("}", ""));
				}
			}
			// 商品热销数
			hotSaleInventory = Integer.parseInt(baseMgr.queryByHql(
					"select sum(hotSaleInventory) from Specification where productId = ? ", new Object[] { productId })[0]
					.toString());
			addOnInv = 0;
			// 找出NM、ADDON、PRESENT可效的AddonProduct
			addOnProdTypeMap = productService.getAddonProductByMainProduct(product);
			// 找出is_delete='N'的SPEC
			prodSpecMap = productService.getAddonProductSpecifciation(product);
			// 找出is_delete='N'的SPECMajor
			prodSpecMajorMap = productService.getAddonProductSpecificationMajor(product);
			// 找出NM、ADDON、PRESENT的SPEC INV
			addOnProdTypeInvMap = productService.getAddonProductInvByMainProduct(product);
			if (StringUtils.isNotBlank(product.getProductBrand()) && product.getProductBrand().startsWith("BD")) {
				brand = productService.getBrandByBrandId(product.getProductBrand());
			} else {
				brand = null;
			}
			// 百分点推荐引擎sessionid
			String sessionId = userData.getSessionId();
			if (null == sessionId || StringUtils.isBlank(sessionId)) {
				userData.writeValue(UserData.NAME_YAODIAN100_SESSION_ID, session.getId());
			}
			prodUserData = userData;

			// 信用卡分期
			creditcard = creditcardService.getValidCreditcard(productId, StringUtils.isBlank(campaignCookie) ? userData
					.getApplySource() : campaignCookie, request.getServerName());
			billBankCodeMenu = menuService.get("99Bill.BankCode");
			billBankSingleCodeMenu = menuService.get("99BillSingle.BankCode");

			if (null != creditcard) {
				chkAvailableDetails = creditcardService.chkAvailableCreditCardDetails(creditcard, product.getViewShelf()
						.getShelfPrice());
			}
			// 大材積
			isVolumeOfProduct = product2Service.chkVolumeOfProduct(productId);
			// 安德仓库商品
			hasAndeProduct = false;
			if ("N".equals(product.getIsScm())) {
				List<String> andeProducts = new ArrayList<String>();
				andeProducts.add(product.getProductId());
				andeProducts = getAllPids(addOnProdTypeMap.get("present"), andeProducts);
				andeProducts = getAllPids(addOnProdTypeMap.get("addon"), andeProducts);
				andeProducts = getAllPids(addOnProdTypeMap.get("nm"), andeProducts);
				for (Campaign cp : productCampaigns) {
					if ("活动赠品".equals(cp.getType().getDesc())) {
						for (CampaignExtend cpid : cp.getTypeExtends()) {
							andeProducts.add(cpid.getCampaignTypeExtension());
						}
					}
				}
				hasAndeProduct = andeProductService.hasAndeProduct(andeProducts);
			}

			// 商品评价
			productComment = orderCommentService.getProductCommentByProductId(product.getProductId());
			commentCampaign = campaignService.getActiveBonusCampaignByM04(null);
			if (null != productComment) {
				star = "0";
				if (productComment.getAvgScore().movePointRight(1).intValue() % 10 > 0) {
					star = "5";
				}

				CommonCriteria crit = new CommonCriteria();

				crit.addEq("productId", productId);
				crit.addEq("hideYn", "N");
				crit.addEq("commentStatus", COMMENT_STATUS.APPROVE.getValue());
				if (StringUtils.isNotBlank(commentTp)) {
					if ("Good".equals(commentTp)) {
						ArrayList<BigDecimal> seList = new ArrayList<BigDecimal>();
						seList.add(new BigDecimal("5"));
						seList.add(new BigDecimal("4"));
						crit.addIn("score", seList);
					}
					if ("Mid".equals(commentTp)) {
						ArrayList<BigDecimal> seList = new ArrayList<BigDecimal>();
						seList.add(new BigDecimal("3"));
						seList.add(new BigDecimal("2"));
						crit.addIn("score", seList);
					}
					if ("Low".equals(commentTp)) {
						crit.addEq("score", new BigDecimal("1"));
					}
				}
				if (pager == null) {
					pager = new SimplePager();
				}

				int entitySize = orderCommentService.getListSize(crit).intValue();
				// pager.setPageRecord(2);
				// pager.setTotalSize(entitySize);
				// commentProductList = orderCommentService.getList(pager.getCurrentPage() * pager.getPageRecord(),
				// pager.getPageRecord(), crit, new String[] { "createDate desc" });

				commentProductList = orderCommentService.getList(0, entitySize, crit, new String[] { "approveDate desc" });

				String logId = "";
				for (OrderComment ocomt : commentProductList) {
					logId = StringUtils.overlay(StringUtils.defaultString(ocomt.getLoginId()), "***",
							ocomt.getLoginId().length() - 3, ocomt.getLoginId().length());
					ocomt.setLoginId(logId);
				}

				// 前三位评价用户
				List<OrderComment> last3Comments = orderCommentService.getLast3CommentByProductId(productId);
				if (null != last3Comments) {
					int sizeLast3Comment = 0;
					if (last3Comments.size() >= 3) {
						sizeLast3Comment = 3;
					} else {
						sizeLast3Comment = last3Comments.size();
					}
					if (sizeLast3Comment > 0) {
						for (int i = 0; i < sizeLast3Comment; i++) {
							OrderComment oc = last3Comments.get(i);
							if (oc.getLoginId().length() < 4) {
								last3Comment = last3Comment + oc.getLoginId().substring(0, 1) + "**" + ",";
							} else {
								last3Comment = last3Comment
										+ StringUtils.overlay(StringUtils.defaultString(oc.getLoginId()), "***" + ",", oc.getLoginId()
												.length() - 3, oc.getLoginId().length());
							}
						}
						last3Comment = last3Comment.substring(0, last3Comment.length() - 1);
					}
				}
			}
			// 加购商品评价
			List<AddOnProductPage> aoppList = addOnProdTypeMap.get("addon");
			if (null != aoppList) {
				ProductComment pc = new ProductComment();
				addProdCommentMap = new HashMap<String, ProductComment>();
				for (AddOnProductPage aioo : aoppList) {
					pc = orderCommentService.getProductCommentByProductId(aioo.getAddOnProductId());
					if (null != pc) {
						addProdCommentMap.put(aioo.getAddOnProductId(), pc);
					}
				}
			}
			// n选m商品评价
			List<AddOnProductPage> nmaoppList = addOnProdTypeMap.get("nm");
			if (null != nmaoppList) {
				ProductComment pc = new ProductComment();
				nmProdCommentMap = new HashMap<String, ProductComment>();
				for (AddOnProductPage aioo : nmaoppList) {
					pc = orderCommentService.getProductCommentByProductId(aioo.getAddOnProductId());
					if (null != pc) {
						nmProdCommentMap.put(aioo.getAddOnProductId(), pc);
					}
				}
			}

			return "product";
		}
	}

	private List<String> getAllPids(List<AddOnProductPage> aops, List<String> andeProducts) {
		if (null != aops && !aops.isEmpty()) {
			for (AddOnProductPage aop : aops) {
				andeProducts.add(aop.getAddOnProductId());
			}
		}
		return andeProducts;
	}

	public String jsonProdRecommend() {
		try {
			if (StringUtils.isNotBlank(prodRecommends)) {
				List<String> productIds = Arrays.asList(prodRecommends.split(","));
				if (null != productIds && productIds.size() > 0) {
					List<String> tmpProductIds = new ArrayList<String>();
					for (String productId : productIds) {
						tmpProductIds.add(StringUtils.trim(productId));
					}
					CommonCriteria crit = new CommonCriteria();
					crit.addIn("productId", tmpProductIds);
					crit.addEq("isDelete", "N");
					List<Product> prodRecommends = product2Service.getList(0, -1, crit, null);
					List<Product> prodRecommendLists = new ArrayList<Product>();
					if (null != prodRecommends && prodRecommends.size() > 0) {
						for (Product product : prodRecommends) {
							if (null != product.getViewShelf()) {
								prodRecommendLists.add(product);
							}
						}
						int i = 1;
						// 最多只取21筆資料出來顯示
						prodRecommendList = new ArrayList<Product>();
						for (String p : tmpProductIds) {
							for (Product tp : prodRecommendLists) {
								if (p.equals(tp.getProductId()) && i <= 21) {
									prodRecommendList.add(tp);
									i++;
								}
							}
						}
					}
				}
			}
		} catch (Exception e) {

		}
		return "jsonProdRecommend";
	}

	Map<String, Boolean> chkDaphneProduct(Product mainProduct) {
		Map<String, Boolean> chkDaphneMap = new HashMap<String, Boolean>();
		List<AddOnProduct> addonProducts = null;
		Product product = null;
		int presentCount = 0;
		SpecificationInventory presentInventory = null;
		String addonResult = "";
		String inventoryResult = "";
		DaphneProduct dp = null;
		CommonCriteria crit = null;
		if (!StringUtils.equalsIgnoreCase(mainProduct.getIsDelete(), "Y")
				&& !StringUtils.equalsIgnoreCase(mainProduct.getIsDelete(), "Q")
				&& !StringUtils.equalsIgnoreCase(mainProduct.getIsScm(), "Y")) {
			if (mainProduct.getProductType() != 6) {
				dp = daphneProductService.getAvailableDaphneProductById(mainProduct.getProductId());
				if (null != dp) {
					for (Specification spec : mainProduct.getSpecifications()) {
						if (!StringUtils.equalsIgnoreCase(spec.getIsDelete(), "Y")) {
							addonResult = addonResult + "y";
							presentInventory = productService.getSpecificationInventory(spec.getProductId(), spec
									.getSpecificationId());
							if (null != presentInventory) {
								presentCount = presentInventory.getInventory();
							}
							if (presentCount > 0 && presentCount >= spec.getMinCountPerOrder()) {
								inventoryResult = inventoryResult + "y";
							} else {
								inventoryResult = inventoryResult + "n";
							}
						} else {
							addonResult = addonResult + "n";
						}
					}
				}
			}
			if (StringUtils.contains(inventoryResult, "y")) {// 主商品有庫存時才檢查贈品及加購
				crit = new CommonCriteria();
				crit.addEq("mainProductId", mainProduct.getProductId());
				crit.addEq("isDelete", "N");
				crit.addLe("startDate", new Date());
				crit.addGe("endDate", new Date());
				if (mainProduct.getProductType() != 6) {
					// get present,addonProduct
					crit.addGe("addOnPrice", new BigDecimal(0));
					crit.addEq("isEnable", "Y");
				} else {
					// get nmProduct
					crit.addEq("addOnPrice", new BigDecimal(-1));
				}
				addonProducts = productService.getAddOnProductList(0, -1, crit, null);
				for (AddOnProduct addonProduct : addonProducts) {
					product = productService.get(addonProduct.getAddOnProductId());
					if (!StringUtils.equalsIgnoreCase(product.getIsDelete(), "Y")
							&& !StringUtils.equalsIgnoreCase(product.getIsDelete(), "Q")
							&& !StringUtils.equalsIgnoreCase(product.getIsScm(), "Y")) {
						dp = daphneProductService.getAvailableDaphneProductById(product.getProductId());
						if (null != dp) {
							for (Specification spec : product.getSpecifications()) {
								if (!StringUtils.equalsIgnoreCase(spec.getIsDelete(), "Y")) {
									addonResult = addonResult + "y";
									presentInventory = productService.getSpecificationInventory(spec.getProductId(), spec
											.getSpecificationId());
									if (null != presentInventory) {
										presentCount = presentInventory.getInventory();
									}
									if (presentCount > 0 && presentCount >= spec.getMinCountPerOrder()) {
										inventoryResult = inventoryResult + "y";
									} else {
										inventoryResult = inventoryResult + "n";
									}
								} else {
									addonResult = addonResult + "n";
								}
							}
						}
					}
				}
			}
		}
		if (StringUtils.countMatches(addonResult, "n") == StringUtils.length(addonResult)
				|| StringUtils.isBlank(addonResult)) {
			chkDaphneMap.put("isDaphne", false);
		} else {
			chkDaphneMap.put("isDaphne", true);
		}
		if (StringUtils.countMatches(inventoryResult, "n") == StringUtils.length(inventoryResult)
				|| StringUtils.isBlank(inventoryResult)) {
			chkDaphneMap.put("invDaphne", false);
		} else {
			chkDaphneMap.put("invDaphne", true);
		}
		// 判斷達芙尼商品售價-折扣後，是否符合達芙尼到店取貨限制
		if (null != chkDaphneMap && chkDaphneMap.size() > 0 && chkDaphneMap.get("isDaphne") == true
				&& chkDaphneMap.get("invDaphne") == true) {// 達芙尼商品
			BigDecimal sumDiscount = BigDecimal.ZERO;
			for (Campaign campaign : productCampaigns) {// 判斷是否有立折立減
				for (CampaignExtend ce : campaign.getTypeExtends()) {
					// 檢核商品金額是否滿足條件
					if (ce.getMinOrderAmount().floatValue() <= mainProduct.getViewShelf().getShelfPrice().floatValue()
							&& mainProduct.getViewShelf().getShelfPrice().floatValue() <= ce.getMaxOrderAmount().floatValue()) {
						switch (campaign.getType()) {
						case C01:
							// 折扣金額為 (product.getViewShelf().getShelfPrice())*(1-ce.campaignTypeExtension/100)
							BigDecimal discount = new BigDecimal(ce.getCampaignTypeExtension()).setScale(1).divide(
									BigDecimal.valueOf(100));
							discount = (mainProduct.getViewShelf().getShelfPrice().multiply(BigDecimal.ONE.subtract(discount)))
									.setScale(1, RoundingMode.HALF_EVEN);
							// 最大 discount 不可超过 商品的售价
							if (discount.compareTo(mainProduct.getViewShelf().getShelfPrice()) > 0) {
								sumDiscount = sumDiscount.add(mainProduct.getViewShelf().getShelfPrice());
							} else {
								sumDiscount = sumDiscount.add(discount);
							}
							break;
						case C02:
							// 折扣金額為 ce.campaignTypeExtension
							sumDiscount = new BigDecimal(ce.getCampaignTypeExtension()).setScale(1);
							break;
						}
					}
				}
			}
			if ((mainProduct.getViewShelf().getShelfPrice().subtract(sumDiscount)).compareTo(ServerValue
					.getDaphneLimitPrice()) < 0) {
				chkDaphneMap = null;
			}
		}
		return chkDaphneMap;
	}

	// 商品預覽
	public String productPreview() {
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		if (StringUtils.isNotBlank(request.getQueryString()) && request.getQueryString().contains("newindex")) {
			String host = request.getHeader("X-Forwarded-For");
			if (StringUtils.isBlank(host)) {
				host = request.getRemoteAddr();
			}

			Pattern pattern = Pattern.compile(ServerValue.getInnerIP());
			Matcher matcher = pattern.matcher(host);
			if (!matcher.find()) {
				return "outSale";
			}
		}

		if (StringUtils.isBlank(productId) || StringUtils.length(productId) < 8 || !NumberUtils.isNumber(productId)) {
			return "outSale";
		}
		Product product = (Product) baseMgr.get(Product.class, productId);
		if (product == null) {
			return "outSale";
		}
		this.product = product;
		// this.shelf = shelfService.getActiveShelfByProductId(productId);
		if (// product.getIsDelete().equals("H") || product.getIsDelete().equals("Y")|| this.shelf == null||
		product.getProductType() == 2 || product.getProductType() == 3) {
			outSaleType = "0";
			if (product.getProductType() == 2 || product.getProductType() == 3) {
				outSaleType = "1";
			} else {
				outSaleType = "0";
			}
			return "outSale";
		} else {
			supplierApply = supplierApplyService.get(product.getSupplierId());
			Category category = (Category) baseMgr.get(Category.class, new Long(product.getMainCategoryID()));
			productCategory = category;
			if ("0".equals(category.getLevel())) {
				if (category.getId() < 10) {
					tempZId = "0" + category.getId().toString();
				} else {
					tempZId = category.getId().toString();
				}
			} else {
				if (Integer.parseInt(category.getCategoryPath().split("/")[0]) < 10) {
					tempZId = "0" + category.getCategoryPath().split("/")[0];
				} else {
					tempZId = category.getCategoryPath().split("/")[0];
				}
			}
			((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().setAttribute("category",
					category);

			// HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(
			// ServletActionContext.HTTP_REQUEST);
			HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
					ServletActionContext.HTTP_RESPONSE);
			HttpSession session = request.getSession();
			UserData userData = new UserData(request, response);
			Map optional = new HashMap();
			optional.put("domain", request.getServerName());
			// campaignCookie for capture
			if (StringUtils.isBlank(campaignCookie)) {
				optional.put("cookie", userData.getApplySource());
			} else {
				optional.put("cookie", campaignCookie);
			}
			// if (product.getProductType() != Integer.valueOf(Product.PRODUCT_TYPE.NPICKM.getValue())) {
			if (z != null && z.length() > 0) {
				productCampaigns = campaignService.getValidCampaign(z, product.getProductId(), optional);
			} else {
				productCampaigns = campaignService.getValidCampaign(category.getCategoryPath(), product.getProductId(),
						optional);
			}
			// }
			Category rootCategory = (Category) baseMgr
					.get(Category.class, new Long(category.getCategoryPath().split("/")[0]));
			pageTitle = product.getProductName() + " - " + rootCategory.getName() + " - 耀点100";
			pageDescription = product.getProductName() + " - " + rootCategory.getName() + " - 耀点100";
			String categorySeo = ServerValue.getSeoProp().getProperty(category.getId().toString() + ".keywords");// for seo 使用
			String categoryNamePath;
			if (z != null) {
				Category categoryOfZ = categoryService.getCategoryById(Long.parseLong(z));
				setCategoryOfZ(categoryOfZ);
				categoryNamePath = categoryService.makeCategorieURL(categoryOfZ.getId(), false);
			} else {
				categoryNamePath = categoryService.makeCategorieURL(category.getId(), false);
			}
			pageKeywords = StringUtils.isNotBlank(categorySeo) ? (categorySeo + ",") : ""
					+ categoryNamePath.replaceAll(" &gt; ", ",")
					+ (StringUtils.isNotBlank(product.getProductKeyword()) ? ("," + product.getProductKeyword()) : "");
			resultDaphne = chkDaphneProduct(product);
			hasTlProduct = timeLimitSaleService.isTimeLimitSale(productId);
			String memberPV = userData.readValue(UserData.NAME_YAODIAN100_MEMBER_PV);
			if (null == memberPV) {
				userData.writeValue(UserData.NAME_YAODIAN100_MEMBER_PV, productId + ",");
			} else {
				if (memberPV.indexOf(productId) == -1) {
					if (StringUtils.countMatches(memberPV, ",") >= 10) {
						// 大於十筆, 保留後九筆商品資料 (八碼+",")*9=81
						if (memberPV.length() > 81) {
							memberPV = memberPV.substring(memberPV.length() - 81);
						}
					}
					userData.writeValue(UserData.NAME_YAODIAN100_MEMBER_PV, memberPV + productId + ",");
				}
			}
			// 我的浏览记录
			String mpv = userData.readValue(UserData.NAME_YAODIAN100_MEMBER_PV);
			if (StringUtils.isNotBlank(mpv)) {
				String[] mpvs = StringUtils.split(mpv, ",");
				mpvList = new ArrayList<ViewShelfProduct>();
				List<ViewShelfProduct> vsps = null;
				CommonCriteria crit = null;
				ArrayUtils.reverse(mpvs);
				for (String pv : mpvs) {
					crit = new CommonCriteria();
					crit.addEq("productId", pv);
					crit.addEq("isDelete", "N");
					vsps = shelfService.getViewShelfProduct(crit, null, 0, 1);
					if (null != vsps && vsps.size() == 1) {
						mpvList.add(vsps.get(0));
					}
				}
				if (mpvList.size() > 10) {
					mpvList = mpvList.subList(0, 10);
					userData.writeValue(UserData.NAME_YAODIAN100_MEMBER_PV, (ArrayUtils.toString(ArrayUtils.subarray(mpvs,
							mpvs.length - 10, mpvs.length))).replaceAll("{", "").replaceAll("}", ""));
				}
			}
			// 商品热销数
			hotSaleInventory = Integer.parseInt(baseMgr.queryByHql(
					"select sum(hotSaleInventory) from Specification where productId = ? ", new Object[] { productId })[0]
					.toString());
			addOnInv = 0;
			// 找出NM、ADDON、PRESENT可效的AddonProduct
			addOnProdTypeMap = productService.getAddonProductByMainProduct(product);
			// 找出is_delete='N'的SPEC
			prodSpecMap = productService.getAddonProductSpecifciation(product);
			// 找出is_delete='N'的SPECMajor
			prodSpecMajorMap = productService.getAddonProductSpecificationMajor(product);
			// 找出NM、ADDON、PRESENT的SPEC INV
			addOnProdTypeInvMap = productService.getAddonProductInvByMainProduct(product);
			if (StringUtils.isNotBlank(product.getProductBrand()) && product.getProductBrand().startsWith("BD")) {
				brand = productService.getBrandByBrandId(product.getProductBrand());
			} else {
				brand = null;
			}
			// 百分点推荐引擎sessionid
			String sessionId = userData.getSessionId();
			if (null == sessionId || StringUtils.isBlank(sessionId)) {
				userData.writeValue(UserData.NAME_YAODIAN100_SESSION_ID, session.getId());
			}
			prodUserData = userData;

			// 信用卡分期
			creditcard = creditcardService.getValidCreditcard(productId, StringUtils.isBlank(campaignCookie) ? userData
					.getApplySource() : campaignCookie, request.getServerName());
			billBankCodeMenu = menuService.get("99Bill.BankCode");
			billBankSingleCodeMenu = menuService.get("99BillSingle.BankCode");

			if (null != creditcard) {
				chkAvailableDetails = creditcardService.chkAvailableCreditCardDetails(creditcard, product.getViewShelf()
						.getShelfPrice());
			}
			// 大材積
			isVolumeOfProduct = product2Service.chkVolumeOfProduct(productId);
			return "productPreview";
		}
	}

	public String productqaa() {
		return "productqaa";
	}

	public String promoteProductInfo() {
		return "promoteProductInfo";
	}

	public String loadProdComment() {
		product = (Product) baseMgr.get(Product.class, productId);
		commentCampaign = campaignService.getActiveBonusCampaignByM04(null);
		// 商品评价
		productComment = orderCommentService.getProductCommentByProductId(productId);
		if (null != productComment) {
			star = "0";
			if (productComment.getAvgScore().movePointRight(1).intValue() % 10 > 0) {
				star = "5";
			}

			CommonCriteria crit = new CommonCriteria();

			crit.addEq("productId", productId);
			crit.addEq("hideYn", "N");
			crit.addEq("commentStatus", COMMENT_STATUS.APPROVE.getValue());
			if (StringUtils.isNotBlank(commentTp)) {
				if ("Good".equals(commentTp)) {
					ArrayList<BigDecimal> seList = new ArrayList<BigDecimal>();
					seList.add(new BigDecimal("5"));
					seList.add(new BigDecimal("4"));
					crit.addIn("score", seList);
				}
				if ("Mid".equals(commentTp)) {
					ArrayList<BigDecimal> seList = new ArrayList<BigDecimal>();
					seList.add(new BigDecimal("3"));
					seList.add(new BigDecimal("2"));
					crit.addIn("score", seList);
				}
				if ("Low".equals(commentTp)) {
					crit.addEq("score", new BigDecimal("1"));
				}
			}
			if (pager == null) {
				pager = new SimplePager();
			}

			int entitySize = orderCommentService.getListSize(crit).intValue();
			pager.setPageRecord(10);
			pager.setTotalSize(entitySize);

			commentProductList = orderCommentService.getList(pager.getCurrentPage() * pager.getPageRecord(), pager
					.getPageRecord(), crit, new String[] { "approveDate desc" });
			String logId = "";
			for (OrderComment ocomt : commentProductList) {
				logId = StringUtils.overlay(StringUtils.defaultString(ocomt.getLoginId()), "***",
						ocomt.getLoginId().length() - 3, ocomt.getLoginId().length());
				ocomt.setLoginId(logId);
			}

			// 前三位评价用户
			List<OrderComment> last3Comments = orderCommentService.getLast3CommentByProductId(productId);
			if (null != last3Comments) {
				int sizeLast3Comment = 0;
				if (last3Comments.size() >= 3) {
					sizeLast3Comment = 3;
				} else {
					sizeLast3Comment = last3Comments.size();
				}
				if (sizeLast3Comment > 0) {
					for (int i = 0; i < sizeLast3Comment; i++) {
						OrderComment oc = last3Comments.get(i);
						if (oc.getLoginId().length() < 4) {
							last3Comment = last3Comment + oc.getLoginId().substring(0, 1) + "**" + ",";
						} else {
							last3Comment = last3Comment
									+ StringUtils.overlay(StringUtils.defaultString(oc.getLoginId()), "***" + ",", oc.getLoginId()
											.length() - 3, oc.getLoginId().length());
						}
					}
					last3Comment = last3Comment.substring(0, last3Comment.length() - 1);
				}
			}
		}
		return "productComment";
	}

	public String myComment() {
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		UserData userData = new UserData(request, response);
		if (null == userData.getMemberId()) {

		} else {
			int maxResult = orderCommentService.getOrderCommentListByMemberId(userData.getMemberId(), "", productId)
					.intValue();
			orderCommentList = orderCommentService.getOrderCommentListByMemberId(userData.getMemberId(), "", productId, 0,
					maxResult);
		}
		return "myComment";
	}

	public String checkMyComment() throws Exception {
		actionResult = "false";
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		UserData userData = new UserData(request, response);

		int iOrderComm = orderCommentService.getOrderCommentListByMemberId(userData.getMemberId(), productId).intValue();
		if (iOrderComm > 0) {
			actionResult = "true";
		}
		return "jsonCheckMyComment";
	}

	public String saveComment() throws IOException {
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		UserData userData = new UserData(request, response);

		if (null == userData.getMemberId()) {

		} else {
			try {
				for (int i = 0; i < orderComtOrderId.length; i++) {
					if (StringUtils.isBlank(nocomment[i])) {
						OrderComment orderComment = new OrderComment();
						orderComment.setOrderId(orderComtOrderId[i]);
						orderComment.setContent(contentdata[i]);
						orderComment.setSubject(orderComtSubject[i]);
						orderComment.setSize(sizedata[i].equals("#") ? "" : sizedata[i]);
						orderComment.setProductId(orderComtProductId[i]);
						orderComment.setScore(new BigDecimal(orderComtScore[i]));
						orderComment.setOrderDetailId(Long.parseLong(orderComtOrderDetailId[i]));
						orderComment.setMemberId(userData.getMemberId());
						orderComment.setLoginId(userData.getLoginId());
						orderComment.setCommentSize("Y");
						orderComment.setHideYn("N");
						orderComment.setMainProductId(mainProductId[i]);
						orderCommentService.saveOrderComment(orderComment);
					}
					redirect_url = "/member/mycomment/commentHistory.do?p=1&msg=xxxx";
				}
			} catch (CoreException e) {
				redirect_url = "/member/mycomment/commentHistory.do?p=1&msg=" + e.getMessage();
			}
			int maxResult = orderCommentService.getOrderCommentListByMemberId(userData.getMemberId(), "",
					orderComtProductId[0]).intValue();
			orderCommentList = orderCommentService.getOrderCommentListByMemberId(userData.getMemberId(), "",
					orderComtProductId[0], 0, maxResult);
		}
		return "saveComment";
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @param isMember the isMember to set
	 */
	public void setIsMember(String isMember) {
		this.isMember = isMember;
	}

	/**
	 * @param outSaleType the outSaleType to set
	 */
	public void setOutSaleType(String outSaleType) {
		this.outSaleType = outSaleType;
	}

	/**
	 * @param product the product to set
	 */
	public void setProduct(Product product) {
		this.product = product;
	}

	/**
	 * @param productCampaigns the productCampaigns to set
	 */
	public void setProductCampaigns(List<Campaign> productCampaigns) {
		this.productCampaigns = productCampaigns;
	}

	/**
	 * @param productId the productId to set
	 */
	public void setProductId(String productId) {
		this.productId = productId;
	}

	/**
	 * @param questionContent the questionContent to set
	 */
	public void setQuestionContent(String questionContent) {
		this.questionContent = questionContent;
	}

	/**
	 * @param sysMessage the sysMessage to set
	 */
	public void setSysMessage(String sysMessage) {
		this.sysMessage = sysMessage;
	}

	/**
	 * @param sysStatus the sysStatus to set
	 */
	public void setSysStatus(String sysStatus) {
		this.sysStatus = sysStatus;
	}

	public void setTempZId(String tempZId) {
		this.tempZId = tempZId;
	}

	/**
	 * @param validValue the validValue to set
	 */
	public void setValidValue(String validValue) {
		this.validValue = validValue;
	}

	/**
	 * @param z the z to set
	 */
	public void setZ(String z) {
		this.z = z;
	}

	public String getPageTitle() {
		return pageTitle;
	}

	public void setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
	}

	public String getNmProductId() {
		return nmProductId;
	}

	public void setNmProductId(String nmProductId) {
		this.nmProductId = nmProductId;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public void setCategoryOfZ(Category categoryOfZ) {
		this.categoryOfZ = categoryOfZ;
	}

	public DaphneProductService getDaphneProductService() {
		return daphneProductService;
	}

	public void setDaphneProductService(DaphneProductService daphneProductService) {
		this.daphneProductService = daphneProductService;
	}

	public boolean isHasTlProduct() {
		return hasTlProduct;
	}

	public void setHasTlProduct(boolean hasTlProduct) {
		this.hasTlProduct = hasTlProduct;
	}

	public TimeLimitSaleService getTimeLimitSaleService() {
		return timeLimitSaleService;
	}

	public void setTimeLimitSaleService(TimeLimitSaleService timeLimitSaleService) {
		this.timeLimitSaleService = timeLimitSaleService;
	}

	public Map<String, Boolean> getResultDaphne() {
		return resultDaphne;
	}

	public void setResultDaphne(Map<String, Boolean> resultDaphne) {
		this.resultDaphne = resultDaphne;
	}

	public ProductService getProductService() {
		return productService;
	}

	public void setProductService(ProductService productService) {
		this.productService = productService;
	}

	public String getPageKeywords() {
		return pageKeywords;
	}

	public void setPageKeywords(String pageKeywords) {
		this.pageKeywords = pageKeywords;
	}

	public String getPageDescription() {
		return pageDescription;
	}

	public void setPageDescription(String pageDescription) {
		this.pageDescription = pageDescription;
	}

	public ShelfService getShelfService() {
		return shelfService;
	}

	public void setShelfService(ShelfService shelfService) {
		this.shelfService = shelfService;
	}

	public List<ViewShelfProduct> getMpvList() {
		return mpvList;
	}

	public void setMpvList(List<ViewShelfProduct> mpvList) {
		this.mpvList = mpvList;
	}

	public String getClearPV() {
		return clearPV;
	}

	public void setClearPV(String clearPV) {
		this.clearPV = clearPV;
	}

	public int getHotSaleInventory() {
		return hotSaleInventory;
	}

	public void setHotSaleInventory(int hotSaleInventory) {
		this.hotSaleInventory = hotSaleInventory;
	}

	public int getAddOnInv() {
		return addOnInv;
	}

	public void setAddOnInv(int addOnInv) {
		this.addOnInv = addOnInv;
	}

	public Shelf getShelf() {
		return shelf;
	}

	public void setShelf(Shelf shelf) {
		this.shelf = shelf;
	}

	public SupplierApply getSupplierApply() {
		return supplierApply;
	}

	public Brand getBrand() {
		return brand;
	}

	public Map<String, Map<Long, Integer>> getAddOnProdTypeInvMap() {
		return addOnProdTypeInvMap;
	}

	public Map<String, List<AddOnProductPage>> getAddOnProdTypeMap() {
		return addOnProdTypeMap;
	}

	public void setAddOnProdTypeInvMap(Map<String, Map<Long, Integer>> addOnProdTypeInvMap) {
		this.addOnProdTypeInvMap = addOnProdTypeInvMap;
	}

	public void setAddOnProdTypeMap(Map<String, List<AddOnProductPage>> addOnProdTypeMap) {
		this.addOnProdTypeMap = addOnProdTypeMap;
	}

	public Map<String, List<Specification>> getProdSpecMap() {
		return prodSpecMap;
	}

	public void setProdSpecMap(Map<String, List<Specification>> prodSpecMap) {
		this.prodSpecMap = prodSpecMap;
	}

	public Creditcard getCreditcard() {
		return creditcard;
	}

	public void setCreditcard(Creditcard creditcard) {
		this.creditcard = creditcard;
	}

	public Map<String, List<SpecificationMajor>> getProdSpecMajorMap() {
		return prodSpecMajorMap;
	}

	public void setProdSpecMajorMap(Map<String, List<SpecificationMajor>> prodSpecMajorMap) {
		this.prodSpecMajorMap = prodSpecMajorMap;
	}

	public Menu getBillBankCodeMenu() {
		return billBankCodeMenu;
	}

	public void setBillBankCodeMenu(Menu billBankCodeMenu) {
		this.billBankCodeMenu = billBankCodeMenu;
	}

	public String getProdRecommends() {
		return prodRecommends;
	}

	public List<Product> getProdRecommendList() {
		return prodRecommendList;
	}

	public void setProdRecommends(String prodRecommends) {
		this.prodRecommends = prodRecommends;
	}

	public void setProdRecommendList(List<Product> prodRecommendList) {
		this.prodRecommendList = prodRecommendList;
	}

	public UserData getProdUserData() {
		return prodUserData;
	}

	public void setProdUserData(UserData prodUserData) {
		this.prodUserData = prodUserData;
	}

	public Map<String, SpecificationInventory> getProdInvMap() {
		return prodInvMap;
	}

	public void setProdInvMap(Map<String, SpecificationInventory> prodInvMap) {
		this.prodInvMap = prodInvMap;
	}

	public String getMainReturnRule() {
		return mainReturnRule;
	}

	public void setMainReturnRule(String mainReturnRule) {
		this.mainReturnRule = mainReturnRule;
	}

	public boolean isVolumeOfProduct() {
		return isVolumeOfProduct;
	}

	public void setVolumeOfProduct(boolean isVolumeOfProduct) {
		this.isVolumeOfProduct = isVolumeOfProduct;
	}

	public Menu getBillBankSingleCodeMenu() {
		return billBankSingleCodeMenu;
	}

	public void setBillBankSingleCodeMenu(Menu billBankSingleCodeMenu) {
		this.billBankSingleCodeMenu = billBankSingleCodeMenu;
	}

	public boolean isChkAvailableDetails() {
		return chkAvailableDetails;
	}

	public void setChkAvailableDetails(boolean chkAvailableDetails) {
		this.chkAvailableDetails = chkAvailableDetails;
	}

	public boolean isHasAndeProduct() {
		return hasAndeProduct;
	}

	public ProductComment getProductComment() {
		return productComment;
	}

	public void setProductComment(ProductComment productComment) {
		this.productComment = productComment;
	}

	public String getStar() {
		return star;
	}

	public void setStar(String star) {
		this.star = star;
	}

	public List<OrderComment> getCommentProductList() {
		return commentProductList;
	}

	public void setCommentProductList(List<OrderComment> commentProductList) {
		this.commentProductList = commentProductList;
	}

	public String getCommentTp() {
		return commentTp;
	}

	public void setCommentTp(String commentTp) {
		this.commentTp = commentTp;
	}

	public String getLast3Comment() {
		return last3Comment;
	}

	public void setLast3Comment(String last3Comment) {
		this.last3Comment = last3Comment;
	}

	public Map<String, ProductComment> getAddProdCommentMap() {
		return addProdCommentMap;
	}

	public void setAddProdCommentMap(Map<String, ProductComment> addProdCommentMap) {
		this.addProdCommentMap = addProdCommentMap;
	}

	public Map<String, ProductComment> getNmProdCommentMap() {
		return nmProdCommentMap;
	}

	public void setNmProdCommentMap(Map<String, ProductComment> nmProdCommentMap) {
		this.nmProdCommentMap = nmProdCommentMap;
	}

	public String getActionResult() {
		return actionResult;
	}

	public void setActionResult(String actionResult) {
		this.actionResult = actionResult;
	}

	public SimplePager getPager() {
		return pager;
	}

	public void setPager(SimplePager pager) {
		this.pager = pager;
	}

	public List<Object> getOrderCommentList() {
		return orderCommentList;
	}

	public void setOrderCommentList(List<Object> orderCommentList) {
		this.orderCommentList = orderCommentList;
	}

	public String[] getOrderComtOrderId() {
		return orderComtOrderId;
	}

	public void setOrderComtOrderId(String[] orderComtOrderId) {
		this.orderComtOrderId = orderComtOrderId;
	}

	public String[] getContentdata() {
		return contentdata;
	}

	public void setContentdata(String[] contentdata) {
		this.contentdata = contentdata;
	}

	public String[] getOrderComtSubject() {
		return orderComtSubject;
	}

	public void setOrderComtSubject(String[] orderComtSubject) {
		this.orderComtSubject = orderComtSubject;
	}

	public String[] getSizedata() {
		return sizedata;
	}

	public void setSizedata(String[] sizedata) {
		this.sizedata = sizedata;
	}

	public String[] getOrderComtScore() {
		return orderComtScore;
	}

	public void setOrderComtScore(String[] orderComtScore) {
		this.orderComtScore = orderComtScore;
	}

	public String[] getOrderComtProductId() {
		return orderComtProductId;
	}

	public void setOrderComtProductId(String[] orderComtProductId) {
		this.orderComtProductId = orderComtProductId;
	}

	public String[] getOrderComtOrderDetailId() {
		return orderComtOrderDetailId;
	}

	public void setOrderComtOrderDetailId(String[] orderComtOrderDetailId) {
		this.orderComtOrderDetailId = orderComtOrderDetailId;
	}

	public String getRedirect_url() {
		return redirect_url;
	}

	public void setRedirect_url(String redirect_url) {
		this.redirect_url = redirect_url;
	}

	public String[] getNocomment() {
		return nocomment;
	}

	public void setNocomment(String[] nocomment) {
		this.nocomment = nocomment;
	}

	public Campaign getCommentCampaign() {
		return commentCampaign;
	}

	public void setCommentCampaign(Campaign commentCampaign) {
		this.commentCampaign = commentCampaign;
	}

	public String[] getMainProductId() {
		return mainProductId;
	}

	public void setMainProductId(String[] mainProductId) {
		this.mainProductId = mainProductId;
	}

}